/**
 * Created by 白雨浓 on 2018/12/5 18:39.
 *
 * 转换
 */

const enumToOptions = (en) => {
  const options = [];

  Object.keys(en).forEach(key => {
    options.push({label: en[key], value: key})
  });

  return options;
};

const arrayToOptions = (array, label, value) => {
  const options = [];
  array.forEach(item => {
    options.push({label: item[label], value: item[value]})
  });
  return options;
};

const setItemsOptions = (items, label, options) => {
  for (const item of items) {
    if (item.item === label) {
      item.options = options;
      return items;
    }
  }
};

const formatApi = (str, ...params) => {
  params.forEach(param => {
    str = str.replace('{}', param);
  });
  return str;
};

export { enumToOptions, arrayToOptions, setItemsOptions, formatApi }